home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 5709 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.5 KB

  1. Path: vb.franken.de!volker
  2. From: volker@vb.franken.de (Volker Barthelmann)
  3. Subject: Re: 680X0 -> PPC translator?
  4. Newsgroups: comp.sys.amiga.programmer
  5. References: <3143E4EB.7303@sapiens.com> <volker.0fsu@vb.franken.de> <31499F8E.26A9@netvision.net.il>
  6. X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
  7. Message-ID: <volker.0fw1@vb.franken.de>
  8. Date: 18 Mar 96 23:11:42 MET
  9. Organization: home
  10.  
  11. Jack (avilev@netvision.net.il) wrote:
  12. :
  13. : oh is that so?! unless you get the address from an outside source, such as allocating it YOU
  14. : must produce it, right?! so you have to have it stored somewhere in the program. if you get it
  15.  
  16. No. I can get it from system functions or calculate it. And both possibilities
  17. can depend on information that is only available at runtime.
  18.  
  19. : from some outside source, such as malloc(), then you don't have it obviously but that being said
  20. : doesn't imply it's impossible to figure out in which context the address is being used (ie code
  21. : or data) and make the proper modifications to the code. also bear in mind that all system
  22. : functions return pointers in either a0 or a1 and then that pointer is saved somewhere in memory
  23. : for later use, if the usage involves executing code in that part of memory then it's easy to
  24.                                                                                        ^^^^
  25. : trace the call to malloc() or what ever else and change the required size according to the
  26.  
  27. Easy??
  28.  
  29. : calculated code size, remember that the code is sitting somewhere inside your executable and
  30. : therefore its size is known, comparing this value to the values pushed to the stack before the
  31. : malloc() call and you would find the exact word address to change.
  32.  
  33. You can't simply change all memory allocations of a certain size, because
  34. the program could use other chunks of memory that happen to have the same
  35. size.
  36. And in many programs You won't find any call to e.g. AllocMem with this
  37. size at all, because the program uses its own memory-pool-routines.
  38. Etc. etc...
  39.  
  40. : > Easy said, but really doing this is a different story. First, You'll have to
  41. : > kind of disassemble the program and therefore You have to know what is data
  42. : > and what is code, but that's what You want to decide, so...
  43. : >
  44. : > Also doing this kind of analysis is pretty much impossible on Assembler code.
  45. : your mind is too cluttered with the complexity of things, but saying it isn't possible is simply
  46. : an unfounded claim.
  47.  
  48. It's not unfounded, but I've thought about some things.
  49. There are much simpler similar problems that are AFAIK proven to be
  50. undecidable.
  51.  
  52. : true things aren't that simple as with dynamic translation, but with a
  53. : little more effort they can be done, quite reliably too. and besides who says that dynamic
  54.  
  55. What do You mean with 'quite reliably'? A translator that creates code
  56. that can be incorrect, but nobody knows when? This would be useless.
  57.  
  58. : approach won't have the same difficulties as the static one, i can see the problem of
  59. : self-modifying code as not so easy to solve even in dynamic translation. that's because, as you
  60. : said what happens if the destination address was dynamically allocated, then you would have to
  61. : change its size again, wouldn't you?!
  62.  
  63. I don't know much about dynamic compilation and didn't say anything about it.
  64. I'd guess those translators know when they have to fall back to
  65. interpretation.
  66.  
  67. : > And a variable in memory in assembler looks like xyz(a7), but only at one
  68. : > point, because at another point it is xyz+c(a7). It is probably impossible
  69. : > to detect if they point to the same address.
  70. :
  71. : so what??? if you follow the changes made to a7, assuming an initial value of 0, you would
  72. : always know what address you're refering to right, doesn't matter how you try to disguise it,
  73. : and if you're keeping track of what is being done with that address location you can figure out
  74. : what the hell it is, either code or data.
  75.  
  76. You can't simply 'keep track' of it, because there are loops and recursions
  77. in a program and if it does some more complicated things it's not possible
  78. to determine where e.g. a7 points to at a certain instruction, because this
  79. depends on the current iteration/recursion or other factors that can't be
  80. known before runtime.
  81.  
  82. : you havn't obviously been listening to what i've said,
  83. : the translator isn't by any measure a stupid one, it must 'understand' the code it's translating
  84.                                                              ^^^^^^^^^^
  85. And this is simply not possible.
  86.  
  87. : and make the proper modification to make it work. of course there will be exceptions to its
  88. : capablity cuz some assumptions are taken for granted, such as register usage etc, but for most
  89. : ansi-compliant programs, it will damn right be a very good tool and most compilers i know are
  90. : ansi-compliant.
  91.  
  92. What do You mean by ansi-compliant programs and what does this have to do
  93. with it?
  94.  
  95. : > Function addresses are often used in arithmetic calculations. Examples are
  96. : > copying of code or control-structures like in special switch-statements.
  97. : are you sure you're talking about functions and not just jump addresses, while similar they're
  98. : NOT the same thing. i'm talking about complete functions and their entry point is fixed and
  99. : therefore can't be calculated.
  100.  
  101. Functions are components of certain high level languages. In machine language
  102. there are only addresses. Even if this code was generated by a compiler You
  103. have to keep track of any jump addresses to be able to determine the
  104. beginning and end of a function and what is code an what is data.
  105.  
  106. Volker
  107.  
  108. P.S.: Please don't use more than about 78 characters/line
  109.  
  110.